package binary;
//位运算符的演示
public class OperDemo {
    public static void main(String[] args) {
        //移位的数学意义:
        int n = 5;
        int m = n<<1;
        int k = n<<2;
        int g = n<<3;
        System.out.println(m); //10----相当于5*2
        System.out.println(k); //20----相当于5*4
        System.out.println(g); //40----相当于5*8
        /*
          权:  64  32  16  8  4  2  1
          n:               0  1  0  1 = 5
          m:           0   1  0  1    = 10
          k:       0   1   0  1       = 20
          g:   0   1   0   1          = 40
         */
















        /*
        //左移位运算:
        int n = 0x6ebc3b3b;
        int m = n<<1;
        int k = n<<2;
        int g = n<<8;
        System.out.println(Integer.toBinaryString(n));
        System.out.println(Integer.toBinaryString(m));
        System.out.println(Integer.toBinaryString(k));
        System.out.println(Integer.toBinaryString(g));
        */








        /*
        //右移位运算:
        int n = 0x6b3f5e3a;
        int m = n>>>1;
        int k = n>>>2;
        int g = n>>>8;
        System.out.println(Integer.toBinaryString(n));
        System.out.println(Integer.toBinaryString(m));
        System.out.println(Integer.toBinaryString(k));
        System.out.println(Integer.toBinaryString(g));
        */




        /*
        //|:或运算--------见1则1
        int n = 0xde;
        int m = 0x9d00;
        int k = n|m; //将n和m错位合并
        System.out.println(Integer.toBinaryString(n));
        System.out.println(Integer.toBinaryString(m));
        System.out.println(Integer.toBinaryString(k));
        */

        /*
        //&:与运算--------见0则0
        int n = 0x17757af6;
        int m = 0xff; //8位掩码
        int k = n&m;
        System.out.println(Integer.toBinaryString(n));
        System.out.println(Integer.toBinaryString(m));
        System.out.println(Integer.toBinaryString(k));
         */
    }
}













